package com.akiyama.controller;




import com.akiyama.service.HttpRequestService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@RestController
public class TestController {


    @Autowired
    private HttpRequestService httpRequestService;

    @RequestMapping("/test")
    public JSONObject abc (@RequestBody String param){
        JSONObject jsonObject = JSONObject.parseObject(param);
        String name = jsonObject.getString("name");
        String passWord = jsonObject.getString("passWord");
        HashMap params = new HashMap();
        params.put("name",name);
        params.put("passWord",passWord);
        try {
            RestTemplate restTemplate = new RestTemplate();
            JSONObject notice = restTemplate.postForObject("https://s.peipeiche.com/api/SysHome/CheckLogin",params,JSONObject.class);
            System.out.println(notice);
            JSONObject js2 = notice.getObject("data",JSONObject.class);
            String token = js2.getString("token");
            HashMap pa = new HashMap();
            pa.put("token",token);
            System.out.println(pa);
            JSONObject js = restTemplate.postForObject("https://s.peipeiche.com/api/SysHome/GetMyAuthMenu",pa,JSONObject.class);
            return js;
        }catch (HttpClientErrorException e){
            System.out.println("http客户端请求出错了！");
            String a = "http客户端请求出错了";
            JSONObject js1 = new JSONObject();
            js1.put("msg",a);
            return js1;
            //开发中可以使用统一异常处理，或者在业务逻辑的catch中作响应
        }
    }


//https://s.peipeiche.com/api/SysHome/CheckLogin   {登录接口}
//
//{Name: "18933776064", Password: "123456"}

}
